package com.tech.thread.juc.locks;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * <p>Title: JUC_Callable_Test </p>
 * <p>Description: </p>
 * Date: 2017年7月22日上午6:25:31
 *
 * @author zl
 * @version 1.0
 * Significant Modify：
 * Date               Author           Content
 * ==========================================================
 * 2017年7月22日           zl        创建文件,实现基本功能
 * <p>
 * ==========================================================
 */
public class JUC_Callable_Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        CallableTest ct = new CallableTest();
        FutureTask<Integer> futureTask = new FutureTask<>(ct);
        new Thread(futureTask).start();
        try {
            int i = futureTask.get();
            System.out.println(i);
            System.out.println("---------");
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

class CallableTest implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        int num = 0;
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            num = num + i;
        }
        return num;
    }
}
